<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子组件向父组件传值-基本用法</title>
</head>
<body>
<div id="app">
    <div :style="{fontSize:fontSize+'px'}">{{pmsg}}</div>
    <menu-item :parr="parr" @enlarge-text="handle($event)"></menu-item>
</div>

<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script type="text/javascript">
    /*
        子组件向父组件传值-基本用法
        props传递数据原则：单向数据流
     */
    Vue.component("menu-item", {
        props: ["parr"],
        template: `
            <div>
                <ul>
                    <li :key="index" v-for="(item,index) in parr">{{item}}</li>
                </ul>
                <button @click="parr.push('smartlsan')">点击</button>
                <button @click="$emit('enlarge-text',5)">扩大父组件中字体大小</button>
                <button @click="$emit('enlarge-text',10)">扩大父组件中字体大小</button>
            </div>
        `
    })

    var vue = new Vue({
        el: "#app",
        data: {
            pmsg: "父容器中的内容",
            parr: ["apple", "huawei", "samsung"],
            fontSize: 10
        },
        methods: {
            handle: function (val) {
                this.fontSize += val;
            }
        }
    });
</script>
</body>
</html>
